package com.h3c.nem.enums;

import com.baomidou.mybatisplus.annotation.EnumValue;
import com.fasterxml.jackson.annotation.JsonCreator;
import com.fasterxml.jackson.annotation.JsonValue;
import lombok.Getter;

import java.util.Map;
import java.util.Optional;
import java.util.function.Function;
import java.util.stream.Collectors;
import java.util.stream.Stream;

/**
 * @author chenyifan
 * @date 2022/6/6 13:39
 * 学位枚举类
 */
@Getter
public enum DegreeLevelEnum {
    CERTIFICATE("V0", "学位证书"),

    GRADUATION("V1", "毕业证书"),

    DROPOUT("V2", "肄业"),

    DUAL_DEGREE("V3", "双学位"),

    COLLEGE_DEGREE("V4", "大专毕业"),

    BACHELORS_DEGREE("V5", "学士学位"),

    PHD("V6", "硕士学位"),

    MASTER_DEGREE("V7", "博士学位"),

    ENGINEERING_MASTER_DEGREE("V8", "工程硕士学位"),

    LAWS_MASTER_DEGREE("V9", "法律硕士学位"),

    MBA_DEGREE("VA", "工商管理硕士学位"),

    EDUCATION_MASTER_DEGREE("VB", "教育硕士学位"),

    ECONOMICS_MASTER_DEGREE("VC", "经济学硕士学位"),

    POSTDOCTORAL_DEGREE("VD", "博士后证书"),

    NO_DEGREE("VE", "无学位证书"),

    ;


    @EnumValue
    @JsonValue
    private final String code;

    private final String typeName;

    DegreeLevelEnum(String code, String typeName) {
        this.code = code;
        this.typeName = typeName;
    }

    /**
     * code 作为 key，封装为 Map
     */
    private static final Map<String, DegreeLevelEnum> CODE_MAP = Stream
            .of(DegreeLevelEnum.values())
            .collect(Collectors.toMap(DegreeLevelEnum::getCode, Function.identity()));


    /**
     * 静态工厂反序列化
     *
     * @param key code
     * @return 评论的类型枚举
     */
    @JsonCreator(mode = JsonCreator.Mode.DELEGATING)
    public static DegreeLevelEnum valueOfKey(String key) {
        return Optional.ofNullable(CODE_MAP.get(key))
                .orElseThrow(() -> new IllegalArgumentException(String.valueOf(key)));
    }
}
